#include "stdinc.h"
#include "Log.h"

#include "platform/misc.h"
#include "cmd/Console.h"

#include <stdarg.h>

#define LOG_FILE	"log.txt"

#if char_UNICODE
#define VSPRINTF(buf, size, fmt, args) vswprintf(buf, size, fmt, args)
#else
#define VSPRINTF(buf, size, fmt, args) vsprintf(buf, fmt, args)
#endif //char_UNICODE

CLog::CLog()
{
	m_file = fopen(LOG_FILE, "wt");
}

CLog::~CLog()
{
	if (m_file)
	{
		fclose(m_file);
	}
}

void CLog::OutputStr(char* str)
{
	OutDbgStr(str);
}

void CLog::Error(char* fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	VSPRINTF(m_tmpBuf, BUF_SIZE, fmt, args);
	va_end(args);

	OutputStr(m_tmpBuf);
}

void CLog::Message(char* fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	VSPRINTF(m_tmpBuf, BUF_SIZE, fmt, args);
	va_end(args);

	OutputStr(m_tmpBuf);
}

void CLog::Debug(char* fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	VSPRINTF(m_tmpBuf, BUF_SIZE, fmt, args);
	va_end(args);

	OutputStr(m_tmpBuf);
}


void CLog::Console(char* fmt, ...)
{
	va_list args;
	va_start(args, fmt);
	VSPRINTF(m_tmpBuf, BUF_SIZE, fmt, args);
	va_end(args);

	OutputStr(m_tmpBuf);
	CONSOLE->Write(m_tmpBuf);
}